package cn.hml.basic.service.impl;

import cn.hml.basic.mapper.BaseMapper;
import cn.hml.basic.query.BaseQuery;
import cn.hml.basic.service.IBaseService;
import cn.hml.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceimpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {

        return baseMapper.loadById(id);

    }

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.sava(t);
    }


    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);

    }

    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.del(id);

    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        //查询总数量前端计算分页栏
        Integer totals = baseMapper.queryCount(baseQuery);
        if (totals==null){

            return new PageList<>();
        }
        //查询当前页的分页数据 前端展示当前页的数据
        List<T> data = baseMapper.queryData(baseQuery);
        return new PageList<>(totals,data);
    }
    @Override
    public void patchDel(Long[] ids) {
        baseMapper.patchDel(ids);

    }
}
